package me.send.framework.util;

import java.io.UnsupportedEncodingException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class Base64Util {

	// 加密
	@SuppressWarnings("restriction")
	public static String getBase64(String value) {
		byte[] b = null;
		String result = null;
		try {
			b = value.getBytes("utf-8");
		} catch (UnsupportedEncodingException exception) {
			exception.printStackTrace();
		}
		if (b != null) {
			result = new BASE64Encoder().encode(b);
		}
		return result;
	}

	// 解密
	@SuppressWarnings("restriction")
	public static String getFromBase64(String value) {
		byte[] b = null;
		String result = null;
		if (value != null) {
			BASE64Decoder decoder = new BASE64Decoder();
			try {
				b = decoder.decodeBuffer(value);
				result = new String(b, "utf-8");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return result;
	}

}
